package com.practice.bootdemo.eventlistener;

import com.practice.bootdemo.dto.UserDto;
import com.practice.bootdemo.eventdto.UserDtoEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

/**
 * @author :Administrator
 * @description: TODO edit class Description
 * @create date: 2021/11/9 15:02
 */

@Component
public class UserDtoEventListener implements ApplicationListener<UserDtoEvent> {

    @Autowired
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;

    @Override
    public void onApplicationEvent(UserDtoEvent userDtoEvent) {
        threadPoolTaskExecutor.execute(() -> {
            try {
                UserDto userDto = userDtoEvent.getUserDto();
                System.out.println("收到事件信息 :"+userDto.getName()+" ," + userDto.getAge());
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
    }
}
